Wrapper for leaflet::leaflet for shorthand declaration of many map layout arguments. Automates many formatting options.
Usage
robomap(
d,
area,
title = NULL,
subtitle = "",
caption = NULL,
hovertext = list(flag = "", unit = ""),
map_opacity = 0.9,
tile_opacity = 0.7,
map_palette = NULL,
border_width = getOption("roboplot.trace.border")$width,
legend_breaks = 5,
legend_position = "bottomright",
data_contour = FALSE,
markers = FALSE,
log_colors = NULL,
rounding = 1,
zoom = TRUE
)Arguments
- d
Data frame. Data to be created a table from.
- area
Symbol, string, or function resulting in symbol or string. Variable from argument 'd' to use to identify the areas described by the map. This must be of class sfc_MULTIPOLYGON.
- title, subtitle
Characters. Labels for plot elements. Optionally, use
set_title()for the title if you want to omit the title from the displayed plot, but include it for any downloads through the modebar.- caption
Function or character. Use a string, or
set_caption().- hovertext
List. Use a list with named items flag and unit.
- map_opacity, tile_opacity
Double. Value from 0 to 1, defining how opaque the map polygon fill color or underlying map tiles are. 0 removes the tile layer, but retains the polygon borders if any.
- map_palette
Character or function. Colors used for heatmap color range. Must be a hexadecimal color strings or a valid css color strings, or use
set_heatmap()if specifying color breakpoints.- border_width
Integer. The width of polygon borders. Default is the trace border width set with
set_roboplot_options().- legend_breaks
Integer vector. If length of 1,
robomap()will break the values into n chunks for the purpose of showing legend, where n is the value of legend_breaks. If length of more than 1, the values are used as the breaks in legend.- legend_position
Character. Currently only accepts "bottom right" or NULL.
- data_contour
Logical. Experimental. If TRUE,
robomap()will produce a contour-like representation of the data, which does not conform to the boundaries of the polygons. This provides a smoother transition and helps in visualizing general trends across regions. Default is FALSE.- markers
Logical. Experimental. Whether markers will be added on the map based on the columns "lat" and "lon". Default is FALSE.
- log_colors
Logical. Whether the colors scales is log or not.
- rounding
Numeric. How
robomap()rounds numeric values.- zoom
Logical. Whether the map is zoomable or not.
Examples
# You can use roboplotr::robomap() to create html maps. Note that very large
# number of map polygons makes for slow rendering maps.
# Currently robomap() only supports very little customization.
vaesto_postinumeroittain |>
dplyr::filter(Alue == "Espoo") |>
robomap(Postinumeroalue, title = "V\u00e4est\u00f6 Espoossa", caption = "Tilastokeskus")
# Default polygon colors are picked from trace colors set with
# set_roboplot_options(), based on luminosity. Control polygon colors with
# map_palette. robomap() expands upon this as necessary.
vaesto_postinumeroittain |>
robomap(
Postinumeroalue,
title = "V\u00e4est\u00f6 postinumeroittain",
subtitle = "Otanta",
caption = "Tilastokeskus",
map_palette = c("lightgreen", "darkred")
)
# You might want to disallow zooming for some reason. The map will be draggable,
# but zoom by buttons or scrolling is disabled.
vaesto_postinumeroittain |>
robomap(
Postinumeroalue,
title = "V\u00e4est\u00f6 postinumeroittain",
subtitle = "Otanta",
caption = "Tilastokeskus",
zoom = FALSE
)
# robomap() automatically scales the values to differentiate large differences
# in maximum and minimum values. Control this with log_colors
vaesto_postinumeroittain |>
robomap(
Postinumeroalue,
title = "V\u00e4est\u00f6 postinumeroittain",
caption = "Tilastokeskus",
map_palette = c("lightgreen", "darkred"),
log_colors = FALSE
)
# Control background tile opacity with 'tile_opacity', polygon opacity with
# 'map_opacity' and borders with 'border_width'.
vaesto_postinumeroittain |>
robomap(
Postinumeroalue,
title = "V\u00e4est\u00f6 postinumeroittain",
caption = "Tilastokeskus",
map_palette = c("lightgreen", "darkred"),
border_width = 2,
tile_opacity = 0.2,
map_opacity = 0.5
)
# Control the story you want to tell by using set_heatmap() with 'map_palette',
# setting the colors and breakpoints. Use legend_breaks to control how many
# entries the legend is split to.
vaesto_postinumeroittain |>
robomap(
Postinumeroalue,
title = "V\u00e4est\u00f6 postinumeroittain",
caption = "Tilastokeskus",
map_palette = set_heatmap(midvalue = 6000, midcolor = "yellow", maxcolor = "red"),
legend_breaks = 3,
map_opacity = 1,
border_width = 0
)
# Or just give the legend breaks
vaesto_postinumeroittain |>
robomap(
Postinumeroalue,
title = "V\u00e4est\u00f6 postinumeroittain",
caption = "Tilastokeskus",
# map_palette = set_heatmap(midvalue = 6000, midcolor = "yellow", maxcolor = "red"),
legend_breaks = c(3001, 6001, 9001),
map_opacity = 1,
border_width = 0
)